home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Picture.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-10
|
6KB
|
256 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "Picture.h"
#include "Class.h"
#include "String.h"
#include "ObjArray.h"
#include "WindowSystem.h"
#include "DevBitmap.h"
#include "PictPort.h"
//---- Picture -----------------------------------------------------------------
NewMetaImpl(Picture,Object, (TV(buf,length), T(bbox), TP(map)));
Picture::Picture()
{
buf= 0;
map= 0;
}
Picture::Picture(Rectangle &b, byte *pagebuf, long len, ObjArray *m)
{
Set(b, pagebuf, len, m);
}
Picture::~Picture()
{
SafeDelete(buf);
SafeDelete(map);
}
void Picture::Set(Rectangle &b, byte *pagebuf, long len, ObjArray *m)
{
SafeDelete(buf);
SafeDelete(map);
map= m;
length= (int) len;
bbox= b;
if (length > 0) {
buf= new byte[length];
memcpy(buf, pagebuf, (u_int) length);
} else
buf= 0;
}
OStream &Picture::PrintOn(OStream &os)
{
Object::PrintOn(os);
os << bbox SP << map SP;
return os.PrintHexString(buf, length);
}
IStream &Picture::ReadFrom(IStream &is)
{
int l;
Object::ReadFrom(is);
is >> bbox >> map;
is.ReadString(&buf, &l);
length= l;
return is;
}
static Point GetPoint(IStream &is, byte code)
{
Point p;
switch ((code & 0x0c) >> 2) {
case 0:
break;
case 1:
p.x= is.GetChar();
break;
case 2:
p.x= (short) is.GetBigEndian(2);
break;
case 3:
p.x= (int) is.GetBigEndian(4);
break;
}
switch (code & 0x03) {
case 0:
break;
case 1:
p.y= is.GetChar();
break;
case 2:
p.y= (short) is.GetBigEndian(2);
break;
case 3:
p.y= (int) is.GetBigEndian(4);
break;
}
return p;
}
void Picture::Show(Rectangle *rp, register Port *port)
{
register int i;
Rectangle r;
Ink *pat= gInkBlack;
byte b, hintbuf[1000];
GrLineCap cap= eDefaultCap;
GrPolyType polytype;
Picture *pict;
Font *font= gSysFont;
int lastlen= 0, psz= 1, startangle= 0, endangle= 0, code, len;
Point dia, p, *pts= 0;
Bitmap *bm;
bool done= FALSE;
MemBuf mb(length, (char*)buf, length);
IStream is(&mb);
GrState gr(port);
port->Scale(1.0/port->GetXScale(), 1.0/port->GetYScale());
port->Translate(rp->origin-bbox.origin-port->GetOrigin());
port->Scale((float) rp->extent.x / (float) bbox.extent.x,
(float) rp->extent.y / (float) bbox.extent.y);
while (!done && is.get(b)) {
switch (b) {
case cPicEnd:
done= TRUE;
continue;
case cPicClip:
port->Clip(gr.clip);
port->ClipFurther(r);
continue;
case cPicFont:
if ((font= (Font*) map->At((short) is.GetBigEndian(2))) == 0)
font= gSysFont;
continue;
case cPicInk:
if ((pat= (Ink*) map->At((short) is.GetBigEndian(2))) == 0)
pat= gInkBlack;
continue;
case cPicStartAngle:
startangle= (short) is.GetBigEndian(2);
continue;
case cPicEndAngle:
endangle= (short) is.GetBigEndian(2);
continue;
case cPicExtent: case cPicExtent+1: case cPicExtent+2: case cPicExtent+3:
case cPicExtent+4: case cPicExtent+5: case cPicExtent+6: case cPicExtent+7:
case cPicExtent+8: case cPicExtent+9: case cPicExtent+10: case cPicExtent+11:
case cPicExtent+12: case cPicExtent+13: case cPicExtent+14: case cPicExtent+15:
r.extent+= GetPoint(is, b);
continue;
case cPicMove: case cPicMove+1: case cPicMove+2: case cPicMove+3:
case cPicMove+4: case cPicMove+5: case cPicMove+6: case cPicMove+7:
case cPicMove+8: case cPicMove+9: case cPicMove+10: case cPicMove+11:
case cPicMove+12: case cPicMove+13: case cPicMove+14: case cPicMove+15:
r.origin+= GetPoint(is, b);
continue;
case cPicLine: case cPicLine+1: case cPicLine+2: case cPicLine+3:
case cPicLine+4: case cPicLine+5: case cPicLine+6: case cPicLine+7:
case cPicLine+8: case cPicLine+9: case cPicLine+10: case cPicLine+11:
case cPicLine+12: case cPicLine+13: case cPicLine+14: case cPicLine+15:
p= r.origin;
r.origin+= GetPoint(is, b);
port->StrokeLine(pat, psz, cap, p, r.origin);
break;
case cPicCornerDia: case cPicCornerDia+1: case cPicCornerDia+2: case cPicCornerDia+3:
case cPicCornerDia+4: case cPicCornerDia+5: case cPicCornerDia+6: case cPicCornerDia+7:
case cPicCornerDia+8: case cPicCornerDia+9: case cPicCornerDia+10: case cPicCornerDia+11:
case cPicCornerDia+12: case cPicCornerDia+13: case cPicCornerDia+14: case cPicCornerDia+15:
dia= GetPoint(is, b);
break;
case cPicPensize:
psz= is.GetByte();
continue;
case cPicPenCap:
cap= (GrLineCap) is.GetByte();
continue;
case cPicStrokeRect:
port->StrokeRect(pat, psz, r);
continue;
case cPicStrokeRRect:
port->StrokeRRect(pat, psz, r, dia);
continue;
case cPicStrokeOval:
port->StrokeOval(pat, psz, r);
continue;
case cPicStrokeWedge:
port->StrokeWedge(pat, psz, cap, r, startangle, endangle);
continue;
case cPicFillPoly:
case cPicStrokePoly:
polytype= (GrPolyType) is.GetByte();
len= (short) is.GetBigEndian(2);
if (len > lastlen) {
SafeDelete(pts);
pts= new Point[lastlen= len];
}
for (i= 0; i < len; i++)
pts[i]= GetPoint(is, is.GetByte());
if (b == cPicStrokePoly)
port->StrokePolygon(r.origin, pat, pts, len, polytype, psz, cap);
else
port->FillPolygon(r.origin, pat, pts, len, polytype);
continue;
case cPicFillRect:
port->FillRect(pat, r);
continue;
case cPicFillOval:
port->FillOval(pat, r);
continue;
case cPicFillRRect:
port->FillRRect(pat, r, dia);
continue;
case cPicFillWedge:
port->FillWedge(pat, r, startangle, endangle);
continue;
case cPicShowBitmap:
if (bm= (Bitmap*) map->At((short) is.GetBigEndian(2)))
port->ShowBitmap(pat, r, bm);
continue;
case cPicShowPicture:
if (pict= (Picture*) map->At((short) is.GetBigEndian(2)))
port->ShowPicture(r, pict);
continue;
case cPicHint:
code= (int) is.GetBigEndian(4);
len= (int) is.GetBigEndian(4);
for(i= 0; i < len; i++)
is.get(hintbuf[i]);
port->GiveHint(code, len, len > 0 ? hintbuf : 0);
continue;
case cPicEsc:
r.origin.x+= port->ShowChar(font, pat, r.origin, is.GetByte());
continue;
default:
if (b >= cPicXMove0 && b < cPicXMove0+64)
r.origin.x+= b-cPicXMove0-32;
else
r.origin.x+= port->ShowChar(font, pat, r.origin, b);
continue;
}
}
}
void Picture::CollectParts(Collection *col)
{
if (map)
col->Add(map);
}